let keyBox = document.getElementById('key-box')
let listBox = document.querySelector('.list-box')
let words = ['600718','000651','600839','600320','601988','000066','601766','601390','000768','000063']

        function search(){
           if(document.getElementById('txtBox')){
               listBox.removeChild(document.getElementById('txtBox'))
           }

           let keyword  = this.value
           let tempWords= []
           for(let word of words){
               if(word.startsWith(keyword)){
                   tempWords.push(word)
               }
           }

           if(this.value =='' || tempWords.length==0){
              if(document.getElementById('txtBox')){
                listBox.removeChild(document.getElementById('txtBox'))
              }
              return
           }

           let txtBox = document.createElement('div')
           txtBox.id  = 'txtBox'
           listBox.appendChild(txtBox)

           for(let i=0;i<tempWords.length;i++){
               let txt = document.createElement('p')
               txt.innerText = tempWords[i]
               txtBox.appendChild(txt)
           }

           //利用事件委托优化，监听词条click事件
           txtBox.onclick =function(e){
             keyBox.value = e.target.innerText
           }
        }

        function debounce(fn,wait){
            let timer = null
            return function(){
                let _this = this
                if(timer){
                    timer = null
                    clearTimeout(timer)
                }
                timer = setTimeout(function(){
                    fn.apply(_this)
                },wait)
            }
        }
        keyBox.oninput = debounce(search,2000)